package com.design.twords.utils;

import android.app.Activity;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import org.litepal.LitePal;
import org.litepal.LitePalApplication;

import java.util.ArrayList;
import java.util.List;

/**
 * Create by Alen
 * Time:  13:35
 */
public class MyApplication extends LitePalApplication {
    private static List<Activity> activities = new ArrayList<>();
    private static Context context;
    private static MyApplication myApplication = new MyApplication();

    public MyApplication(){}
    public static MyApplication getInstance(){
        return myApplication;
    }

    public void addActivity(Activity activity){
        activities.add(activity);
    }
    @Override
    public void onCreate() {
        super.onCreate();
//        context.getApplicationContext();
        LitePal.initialize(this);
        SQLiteDatabase db = LitePal.getDatabase();
    }

    public void removeActivity(Activity activity){
        if (activities.contains(activity)){
            activities.remove(activity);
            activity.finish();
        }
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        for(Activity activity:activities){
            activity.finish();
        }
        System.exit(0);

    }


}
